/*
-----------------------------------------------------------------------------
This source file is part of Labor3D
(Labor 3D Graphics Engine)

Copyright (c) 2011-2020 Rock Mao
* creator : Rock Mao
* created : 2011-5-2   22:29
* filename: LaborD3D11IndexBuffer.h
-----------------------------------------------------------------------------
*/
#ifndef __LABORD3D11INDEXBUFFER_H__
#define __LABORD3D11INDEXBUFFER_H__

#include "LaborD3D11Def.h"
#include "Renderer\LaborIndexBuffer.h"
#include "LaborD3D11HardwareBuffer.h"

NAMESPACE_LABOR3D_BEGIN

class CLD3D11IndexBuffer : public CLIndexBuffer
{

protected:
	CLD3D11HardwareBuffer* mBufferImpl;
	// have to implement these, but do nothing as overridden lock/unlock
	void* lockImpl(size_t offset, size_t length, EHB_LockOptions options) {return 0;}
	void unlockImpl(void) {}
public:
	CLD3D11IndexBuffer(eLIndexType idxType, size_t numIndexes, 
		EHB_Usage usage, CLD3D11Device & device, bool useSystemMem, bool useShadowBuffer);
	~CLD3D11IndexBuffer();
	// override all data-gathering methods
	void* lock(size_t offset, size_t length, EHB_LockOptions options);
	void unlock(void);
	void readData(size_t offset, size_t length, void* pDest);
	void writeData(size_t offset, size_t length, const void* pSource,
		bool discardWholeBuffer = false);

	void copyData(CLHardwareBuffer& srcBuffer, size_t srcOffset, 
		size_t dstOffset, size_t length, bool discardWholeBuffer = false);
	bool isLocked(void) const;

	/// For dealing with lost devices - release the resource if in the default pool
	bool releaseIfDefaultPool(void);
	/// For dealing with lost devices - recreate the resource if in the default pool
	bool recreateIfDefaultPool(CLD3D11Device & device);

	/// Get the D3D-specific index buffer
	ID3D11Buffer * getD3DIndexBuffer(void) const;
};
NAMESPACE_LABOR3D_END
#endif // __LABORD3D11INDEXBUFFER_H__
